import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/23 23:16
 * @description 排序
 */
public class Solution {
    public static void main(String[] args) {
        Solution so = new Solution();
        int[] arr = {1, 2, 3, 4, 5};
        so.getStrongest(arr, 2);
    }
    public int[] getStrongest(int[] arr, int k) {
        Arrays.sort(arr);
        int n = arr.length;
        int mid = arr[(n - 1) / 2];
        List<Integer> list = new ArrayList<>();
        for (int a: arr) {
            list.add(a);
        }
        Collections.sort(list, (a, b) -> {
            int x = Math.abs(a - mid), y = Math.abs(b - mid);
            if ( y > x  || (y == x && b > a)) {
                return 1;
            }
            return -1;
        });
        int[] ans = new int[k];
        for (int i = 0; i < k; i++) {
            ans[i] = list.get(i);
        }
        return ans;
    }
}
